package com.hanamaki.unit.testng.homework.ct;

import com.unit.junit.util.FileUtil;
import com.unit.junit.util.JdbcUtil;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;

public class SquareTest {
    static Square square;

    @BeforeMethod
    public void getUp() {
        square = new Square();
    }

    @Test(dataProvider = "dp1")
    public void testdp1(double a, double b, boolean result, double perimeter, double area) {
        boolean isSquare = SquareTest.square.isSquare(a, b);
        Assert.assertEquals(isSquare, result);
        if (isSquare) {
            double perimeter1 = square.perimeter();
            Assert.assertEquals(perimeter1, perimeter);
            double area1 = square.area();
            Assert.assertEquals(area1, area);
        }
    }
    @Test(dataProvider = "dp2")
    public void testdp2(String a, String b, String result, String perimeter, String area) {
        boolean isSquare = SquareTest.square.isSquare(Double.parseDouble(a),Double.parseDouble(b));
        Assert.assertEquals(isSquare, result);
        if (isSquare) {
            double perimeter1 = square.perimeter();
            Assert.assertEquals(perimeter1, Double.parseDouble(perimeter));
            double area1 = square.area();
            Assert.assertEquals(area1,Double.parseDouble(area));
        }
    }
    @Test(dataProvider = "dp3")
    public void testdp3(String a, String b, String result, String perimeter, String area) {
        boolean isSquare = SquareTest.square.isSquare(Double.parseDouble(a),Double.parseDouble(b));
        Assert.assertEquals(isSquare, result);
        if (isSquare) {
            double perimeter1 = square.perimeter();
            Assert.assertEquals(perimeter1, Double.parseDouble(perimeter));
            double area1 = square.area();
            Assert.assertEquals(area1,Double.parseDouble(area));
        }
    }

    @DataProvider
    public Object[][] dp1() {
        return new Object[][]{
                new Object[]{1, 2, true, 6,2},
                new Object[]{3, 4, true, 2 * 3 * 4,1},
                new Object[]{0, 2, true, 0 * 4 * 1,1},
        };
    }


    @DataProvider
    public Object[][] dp2() {
        return FileUtil.getFileContent("src/com/unit/testng/work/test2.txt");
    }

    @DataProvider
    public Object[][] dp3() {
        return JdbcUtil.getSqlContent("circle1");
    }
}
